package leecode

func getIntersectionNodeLCR(headA, headB *ListNode) *ListNode {
	//创建虚拟头节点
	nodeA := &ListNode{Next: headA}
	nodeB := &ListNode{Next: headB}
	nodeHeadA, nodeHeadB := nodeA, nodeB
	for nodeHeadA != nodeHeadB {
		if nodeHeadA != nil {
			nodeHeadA = nodeHeadA.Next
		} else {
			//当A节点遍历完毕之后,使其指向B的头节点
			nodeHeadA = nodeB
		}
		if nodeHeadB != nil {
			nodeHeadB = nodeHeadB.Next
		} else {
			//当A节点遍历完毕之后,使其指向B的头节点
			nodeHeadB = nodeA
		}
	}
	return nodeHeadA
}
